import * as types from '../../mutation-types'

const initUser = {
  userInfo: {},
  token: '',
  language: 'zhCN',
  theme: 'standard'
}
const userReducer = (preState = initUser, action) => {
  const { type, data } = action
  switch (type) {
    case types.SET_USER_INFO:
      return {
        ...preState,
        userInfo: data
      }
    case types.SET_LANGUAGE:
      return {
        ...preState,
        language: data
      }
    case types.SET_TOKEN:
      return {
        ...preState,
        token: data
      }
    case types.SET_PAGE_THEME:
      return {
        ...preState,
        theme: data
      }
    default:
      return preState
  }
}

export default userReducer